package com.cictec.middleware.tde.rm.protocol.rm.decode;

import java.nio.ByteBuffer;

import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cictec.middleware.commons.utils.BinaryUtils;
import com.cictec.middleware.tde.exception.MessageDecoderException;
import com.cictec.middleware.tde.rm.protocol.AbstractMessageDecoder;
import com.cictec.middleware.tde.rm.protocol.TerminalMessage;
import com.cictec.middleware.tde.rm.protocol.TerminalMessage.Header;
import com.cictec.middleware.tde.rm.protocol.annotion.TerminalMessageDecoder;
import com.cictec.middleware.tde.rm.protocol.rm.message.Rm0x82PlatformMessage;

/**
 * 0x82 设置定时上 传 周期
 * 
 * @author ql
 *
 */
@TerminalMessageDecoder(0x82)
public class Rm0x82Decoder extends AbstractMessageDecoder {

	private static Logger logger = LoggerFactory.getLogger(Rm0x82Decoder.class);

	@Override
	public TerminalMessage decode(Header header, ByteBuffer in, IoSession session) throws MessageDecoderException {

//		byte[] ioBufferByte = new byte[in.limit()];
//		in.get(ioBufferByte);
//		logger.debug("【客户端-{}】【解码】【前】收到消息：{}", session.getAttribute(Constants.TerminalId), BinaryUtils.byte2HexStr(ioBufferByte));
//		in.position(0);// 默认从0开始读取，如果设置debug，并修改了代码，需要重新从设置0开始读取数据

		byte[] interval = new byte[2];
		in.get(interval);
		Rm0x82PlatformMessage msg = new Rm0x82PlatformMessage(header);
		msg.setUploadInterval(BinaryUtils.wordToInt(interval));
		msg.setReserved(BinaryUtils.wordToInt(in));

		logger.debug("【0x82】位置数据上传周期{}", msg.getUploadInterval());

		return msg;
	}

}
